<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="80px">

      <el-form-item label="订单号">
        <el-input v-model="queryParams.orderNo" clearable></el-input>
      </el-form-item>
        <el-form-item label="供应商">
            <el-select v-model="queryParams.supplierId" style="width: 180px" clearable>
                <el-option value="" label="--请选择--"></el-option>
                <el-option v-for="(item,index) in supplierList" :key="index" :label="item.supplier" :value="item.id"></el-option>
                
            </el-select>
        </el-form-item>
         <el-form-item label="订单状态">
            <el-select v-model="queryParams.orderStatus" style="width: 140px" clearable>
                <el-option value="" label="--请选择--"></el-option>
                <el-option value="1" label="订单提交"></el-option>
                <el-option value="2" label="订单商品全部验收"></el-option>
                <el-option value="3" label="订单商品部分验收"></el-option>
                <el-option value="4" label="订单商品全部拒收"></el-option>
            </el-select>
        </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="AttenceStaList" >
      <el-table-column label="订单号" align="center" prop="orderNo" width="200" :show-overflow-tooltip="true" />
      <el-table-column label="供应商名称" align="center" prop="supplier" :show-overflow-tooltip="true" />
      <el-table-column label="供应商电话" align="center" prop="supplierPhone" :show-overflow-tooltip="true" />
      <el-table-column label="订单状态" align="center" prop="orderStatus" :show-overflow-tooltip="true" >
          <template slot-scope="scope">
            <el-tag v-if="scope.row.orderStatus==1" >订单提交</el-tag>
            <el-tag v-if="scope.row.orderStatus==2" type="success">订单商品全部验收</el-tag>
            <el-tag v-if="scope.row.orderStatus==3">订单商品部分验收</el-tag>
            <el-tag v-if="scope.row.orderStatus==4">订单商品全部拒收</el-tag>
          </template>
      </el-table-column>
      <el-table-column label="提单人" align="center" prop="createBy" :show-overflow-tooltip="true" />
      <el-table-column label="提单时间" align="center" prop="createdTime" :show-overflow-tooltip="true" >
        <template slot-scope="scope">
          {{parseTime(scope.row.createdTime)}}
        </template>
      </el-table-column>
      <el-table-column label="预计收货日期" align="center" prop="orderReceivDate" :show-overflow-tooltip="true" />
      <el-table-column label="收货签名" align="center" prop="receivSign" width="100" :show-overflow-tooltip="true" >
          <template slot-scope="scope">
             {{scope.row.receivSign}}
          </template>
      </el-table-column>
      <el-table-column label="操作" align="center" >
        <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="查看商品" placement="top">
                <el-button
                        size="mini"
                        circle type="primary"
                        icon="el-icon-view"
                        @click="handleView(scope.row)"
                        
                />
            </el-tooltip>
        </template>
      </el-table-column>

    </el-table>


    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    

    <!--批量订单查看-->
    <el-dialog title="订单商品" :visible="viewVisibleDialog" width="80%" :before-close="handleClose">
      <el-table v-loading="loading" :data="goodsCheckList" @selection-change="handleViewTableRow">
        <el-table-column label="物品名称" align="center" prop="goodsName" :show-overflow-tooltip="true" />
        <el-table-column label="物品类型" align="center" prop="goodsType" :show-overflow-tooltip="true" >
            <template slot-scope="scope">
              <el-tag v-if="scope.row.goodsType==1" type="success">生鲜商品</el-tag>
              <el-tag v-if="scope.row.goodsType==2">普通商品</el-tag>
            </template>
        </el-table-column>
        <el-table-column label="生产日期" align="center" prop="goodsDate" :show-overflow-tooltip="true" />
        <el-table-column label="保质期(天)" align="center" prop="shelfLife" :show-overflow-tooltip="true" />
        <el-table-column label="数量+单位" align="center" prop="goodsNumber" :show-overflow-tooltip="true" >
            <template slot-scope="scope">
                {{scope.row.goodsNumber}}{{scope.row.goodsSpec}}
            </template>
        </el-table-column>
        <el-table-column label="验收是否通过" align="center" prop="checkPass" :show-overflow-tooltip="true" >
          <template  slot-scope="scope">
            <el-tag v-if="scope.row.checkPass==1" type="success">通过</el-tag>
            <el-tag v-if="scope.row.checkPass!=1" type="info">未通过</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="验收原因" align="center" prop="check_desc" :show-overflow-tooltip="true" />
        <el-table-column label="验收图片集" align="center" prop="goodsNumber" :show-overflow-tooltip="true" >
            <template slot-scope="scope">
                <el-image 
                  style="width: 40px; height: 40px"
                  v-if="scope.row.goodsDateImg"
                  :src="getImgPath(scope.row.goodsDateImg)" 
                  :preview-src-list="[getImgPath(scope.row.goodsDateImg)]">
                </el-image>
                 <el-image 
                  style="width: 40px; height: 40px"
                   v-if="scope.row.shelfLifeImg"
                  :src="getImgPath(scope.row.shelfLifeImg)" 
                  :preview-src-list="[getImgPath(scope.row.shelfLifeImg)]">
                </el-image>
                 <el-image 
                  style="width: 40px; height: 40px"
                  v-if="scope.row.productionUnitImg"
                  :src="getImgPath(scope.row.productionUnitImg)" 
                  :preview-src-list="[getImgPath(scope.row.productionUnitImg)]">
                </el-image>
            </template>
        </el-table-column>
      </el-table>
    </el-dialog>

  </div>
</template>



<script>
  // import bargraph from '../../dashboard/AttendanceChart'
  import { getOrderPageList,createOrUpdateCanteenBuyInfo,goodsPutStock,getOrdeGoodsrPageList } from "@/api/canteen/canteenBuy";
  import { getsupplierPageList} from "@/api/canteen/supplier";

  export default {
    name: "duty",
    data(){
      return{
        // 遮罩层
        loading: true,
        viewVisibleDialog:false,
        tagType:'save',
        uploadPath:'http://localhost:9004/app/common/uploadFile',
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        AttenceStaList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          accessDate: undefined
        },
        userList:[],
        dutyVisible:false,
        formData:{},
        rules:{
            userId:[{ required: true, message: '请选择值班老师', trigger: 'blur' }],
            dutyDate:[{ required: true, message: '请选择值班日期', trigger: 'blur' }],
            dutyType:[{ required: true, message: '请选择值班值班角色', trigger: 'blur' }],
            dutyDept:[{ required: true, message: '请选择值班部门', trigger: 'blur' }],
        },
        restaurants:null,
        goodsUnitList:undefined,
        viewDataList:[],
        supplierList:[],
        goodsCheckList:[]
        
      }
    },
    components:{
      // bargraph
    },
    created() {
        this.getList()
        this.getSupplierList()
    },
    methods: {
        
      /** 查询任务量列表 */
      getList() {
        this.loading = true;
        getOrderPageList(this.queryParams).then(response => {
            this.AttenceStaList = response.data.list;
            this.total = response.data.total;
            this.loading = false;
         
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      handleAdd(){
          this.dutyVisible = true
          this.formData={}
      },
      submitForm(){
        //   this.$refs["dutyFormData"].validate((valid) => {
        //       if(valid){
                  createOrUpdateCanteenBuyInfo(this.formData).then(resp=>{
                    if(resp.code==200){
                    this.getList()
                    this.$message({  message: '提交成功', type: 'success'});
                    this.formData={}
                    this.dutyVisible=false
                   }
                })
        //       }
        //   })

          
      },
      cancel(){
        this.dutyFormData={}
        this.dutyVisible=false
      },
      handleUpdate(row){
        this.dutyVisible=true
        this.formData = row
        this.tagType='save'
      },
      handleSignUpdate(row){
        this.dutyVisible=true
        this.formData = row
        this.tagType='sign'
      },
      handleDelete(row){
          deleteSchoolDutyById(row).then(resp=>{
              if(resp.code==200){
                this.$message({  message: '提交成功', type: 'success'});
                this.getList()
                
              }
          })
      },
      querySearch(queryString, cb) {
        var restaurants = this.restaurants;
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
        // 调用 callback 返回建议列表的数据
        cb(results);
      },
      createFilter(queryString) {
        return (restaurant) => {
          return (restaurant.supplier.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
      },

      handleSelect(item) {
          this.formData = item
        console.log(item);
      },
      handleIconClick(ev) {
        console.log(ev);
      },
      handleRemoveGoods(file, fileList){
        //删除商品图片
        this.getFileListToForm(fileList,'goods')
      },
      handleRemoveBill(file, fileList){
        //删除单据图片
        this.getFileListToForm(fileList,'bill')
      },
      handleSuccessBill(response,file,fileList){
        //单据上传成功
        this.getFileListToForm(fileList,'bill')
      },
      handleSuccessGoods(response,file,fileList){
        //物品上传成功
        this.getFileListToForm(fileList,'goods')
      },
      getFileListToForm(fileList,type){
          let imgs;
          for(let i=0;i<fileList.length;i++){
              imgs=fileList[i].response.data+","
          }
          if(type=='goods'){
              this.formData.goodsImg=imgs.substring(0,imgs.length-1)
          }
          if(type=='bill'){
              this.formData.billImg=imgs.substring(0,imgs.length-1)
          }
      },
      submitGoodsPutStock(){
        this.formData.isPut = 1
        //提交入库
        goodsPutStock(this.formData).then(resp=>{
            if(resp.code==200){
                this.$message({  message: '入库成功', type: 'success'});
                this.getList()
                this.formData={}
                this.dutyVisible=false
            }
        })
      },
      handleSearch(row){
        this.dutyVisible=true
        this.formData = row
        this.tagType='search'
      },
      handleView(row){
        this.viewVisibleDialog = true
        getOrdeGoodsrPageList({orderNo:row.orderNo}).then(resp=>{
          this.goodsCheckList = resp.data
          console.log(this.goodsCheckList)
        })
       
      },
      handleViewTableRow(rows){
        this.viewDataList=[]
        this.viewDataList = rows
      },
      handleClose(){
         this.viewVisibleDialog = false
         this.viewDataList=[]
      },
      getSupplierList() {
        this.loading = true;
        getsupplierPageList({pageNum: 1, pageSize: 1000}).then(response => {
            this.supplierList = response.data.list;
        });
      },
      getImgPath(filename){
        let path = window.location.host
        if(path.indexOf("49")>=0){
          path = 'http://49.4.65.194:9092/app/common/downloadFileImg?filename='+filename
        } else if(path.indexOf("117")>=0){
          path = 'http://117.78.19.207:9091/app/common/downloadFileImg?filename='+filename
        } else{
          path = 'http://localhost:9091/app/common/downloadFileImg?filename='+filename
        }
        console.log(path)
        return path
      },
        
    }
  }
</script>

<style>
.my-autocomplete li {
    line-height: normal;
    padding: 7px;
}
  .name {
      text-overflow: ellipsis;
      overflow: hidden;
    }
 .addr {
      font-size: 12px;
      color: #b4b4b4;
    }

.my-autocomplete li .highlighted .addr {
      color: #ddd;
    }

</style>